Application programming interfaces (APIs) that require waiting for a non-deterministically and relatively long time, such as accessing network resources or reading files from a storage media, in an application can be performed as synchronous or asynchronous operations.
Synchronous operations stall the application and other operations until the synchronous operation is complete. Synchronous syntax in computer programs is generally straightforward and familiar to developers, and many developers have little or no difficulties writing synchronous operations. An application using synchronous operations, however, can hold on to valuable computing resources while the synchronous operations complete, and thus synchronous operations can be very expensive if the network resources of files are not readily available.
Asynchronous operations, on the other hand, are used to avoid stalling the application and allow the computing resources to perform other useful work while the operation completes. For example, if an asynchronous operation pauses because the application is waiting for a response from a local storage media, a website server, or the like, the computing resources are released to perform other valuable work, and the asynchronous operation will resume with the computing resources after the application has received the file or download.
Managed environments, such as .NET available from Microsoft Corporation of Redmond, Wash., provide for several ways of defining and implementing asynchronous operations. A commonly used way is to use an Asynchronous Programming Model (APM). The APM defines an asynchronous operation as including two functions with the typical shape as:
IAsyncResult BeginXXX(<<args-1>>, AsynchCallback cb, object state);int EndXXX (IAsyncResult ar, <<args-2>>);where IAsynchResult represents the status of the operation, “XXX” is the name of the operation, “args-1” is the list of the in- and ref-parameters, and “args-2” is the list of the out- and ref-parameters of the operation.
Although asynchronous operations provide the benefit of increased workflow, asynchronous operations as currently defined and implemented presents difficulties for many developers. One difficulty includes scaling, or providing for multiple requests, and chaining together requests in a loop as complications quickly arise as more requests are introduced. Also, many developers find composing larger asynchronous operations from existing APM-based operations to be a challenge. As the present trend toward integration of software applications with remote serves in an Internet cloud continues, there is a need for more asynchronous code.